var inorderTraversal = function(root,res=[]) {
    if(!root)return res
inorderTraversal(root.left,res)
res.push(root.val)
inorderTraversal(root.right,res)
return res
};

// 迭代
/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number[]}
 */
var inorderTraversal = function(root) {
    //   迭代 左中右
    const res=[],stack=[]
    if(!root)return res
    while (root) {        // 能压栈的左子节点都压进来
        stack.push(root);
        root = root.left;
      }
    
    while(stack.length){
        let node=stack.pop()
        res.push(node.val)
        node=node.right
        while(node){
            stack.push(node)
            node=node.left
        }
    }
    return res
    
    
    
    
    
    };